home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Random fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  2.4 KB  |  80 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Random fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define        SUB_HOR        20
  32. #define        SUB_VER        20
  33. #define        AREA        (SUB_HOR * SUB_VER)
  34. #define CorrectTime 1
  35. #define theWindowWidth (boundsRect.right-boundsRect.left)
  36. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  37.  
  38. pascal short RandomFade(Rect boundsRect, Pattern *thePattern);
  39.  
  40. /* Basically, we divide the window into a bunch of blocks, and copy
  41. each to the screen in random order. */
  42.  
  43. pascal short RandomFade(Rect boundsRect, Pattern *thePattern)
  44. {
  45.     int                order[AREA];
  46.     int                i;
  47.     long            randtemp;
  48.     int                ordertemp;
  49.     Rect            subBox;
  50.     Rect            dest;
  51.     Boolean            everyOther;
  52.     
  53.     everyOther=FALSE;
  54.     for(i = 0; i < AREA; i++)
  55.         order[i] = i;
  56.     
  57.     for(i = (AREA - 1); i >= 0; i--) {
  58.         randtemp = ((((long)Random()) +32767) * (i + 1)) / 65535;
  59.         
  60.         ordertemp = order[randtemp];
  61.         order[randtemp] = order[i];
  62.         order[i] = ordertemp;
  63.     }
  64.     
  65.     for(i = 0; i < AREA; i++) {
  66.         StartTiming();
  67.         subBox.top = ((order[i] / SUB_VER) * theWindowHeight) / SUB_VER;
  68.         subBox.left = ((order[i] % SUB_HOR) * theWindowWidth) / SUB_HOR;
  69.         subBox.bottom = (((order[i] / SUB_VER) + 1) * theWindowHeight) / SUB_VER;
  70.         subBox.right = (((order[i] % SUB_HOR) + 1) * theWindowWidth) / SUB_HOR;
  71.         OffsetRect(&subBox, boundsRect.left, boundsRect.top);
  72.         FillRect(&subBox, *thePattern);
  73.         if (everyOther)
  74.             TimeCorrection(CorrectTime);
  75.         everyOther=!everyOther;
  76.     }
  77.     
  78.     return 0;
  79. }
  80.